<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<%@ page import="java.util.*"%>
<%@ page import="cn.myapps.core.validate.repository.action.ValidateRepositoryHelper" %>
<ww:bean name="cn.myapps.core.dynaform.form.action.FormHelper" id="fh">
	<ww:param name="moduleid" value="#parameters.moduleid"/>
</ww:bean>
<html><o:MultiLanguage>
<HEAD>
<META http-equiv=Content-Type content="text/html; charset=UTF-8">
<META HTTP-EQUIV="pragma" CONTENT="no-cache"> 
<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate"> 
<META HTTP-EQUIV="expires" CONTENT="0">
<link href="../css/dialog.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href='<ww:url value="/resource/css/main.css" />' type="text/css">
<script src='<ww:url value="/dwr/util.js"/>'></script>
<script src='<ww:url value="/dwr/engine.js"/>'></script>
<script src='<ww:url value="/dwr/interface/Sequence.js"/>'></script>
<script src='<ww:url value="/dwr/interface/FormHelper.js"/>'></script>

<script language=JavaScript src="../../dialog/sequence.js"></script>
<script language=JavaScript src="../../dialog/dialog.js"></script>
<script language=JavaScript src="../../dialog/script.js"></script>
<script src="../../dialog/common/fck_dialog_common.js" type="text/javascript"></script>
<link href="../../css/dialog.css" rel="stylesheet" type="text/css" />

<SCRIPT language=JavaScript>
var dialog	= window.parent ;
var oEditor = dialog.InnerDialogLoaded();
// Gets the document DOM
var oDOM = oEditor.FCK.EditorDocument;
var oActiveEl = dialog.Selection.GetSelectedElement() ;

// 选项卡点击事件
function cardClick(cardID){
	var obj;
	for (var i=1;i<8;i++){
		obj=document.all("card"+i);
		obj.style.backgroundColor="#3A6EA5";
		obj.style.color="#FFFFFF";
	}
	obj=document.all("card"+cardID);
	obj.style.backgroundColor="#FFFFFF";
	obj.style.color="#3A6EA5";

	for (var i=1;i<8;i++){
		obj=document.all("content"+i);
		obj.style.display="none";
	}
	obj=document.all("content"+cardID);
	obj.style.display="";
	resize();
}

function getCreateNamedElement() {
	var className="cn.myapps.core.dynaform.form.ejb.SuggestField";
	var id = oActiveEl ? oActiveEl.id: getFieldId();
	var editMode=document.getElementsByName("editMode");
	var ed="";
    for(var i=0;i<editMode.length;i++){
		if(editMode[i].checked){
			ed = editMode[i].value;
			break;
	    }
	}
		  
	var validateLibs=document.getElementsByName('validateLibs');
	var libs='';
	for(var i=0; i< validateLibs.length; i++){
   		if(validateLibs[i].checked){
   			libs+=validateLibs[i].value+";";
   		}
   	}
   	libs=libs.substring(0,libs.length-1);
	
	return CreateNamedElement( oEditor, oActiveEl, 'input', {
		classname: className,
		type: "text",
		id: id,
		name: GetE('name').value,
		discript:HTMLEncode(temp.discript.value),
		valueScript:HTMLEncode(temp.valueScript.value),
		optionsScript:HTMLEncode(temp.optionsScript.value),
		validateRule:HTMLEncode(temp.validateRule.value),
		hiddenScript:HTMLEncode(temp.hiddenScript.value),
		hiddenValue:HTMLEncode(temp.hiddenValue.value),//////
		hiddenPrintScript:HTMLEncode(temp.hiddenPrintScript.value),
		printHiddenValue:HTMLEncode(temp.printHiddenValue.value),
		textType:HTMLEncode(temp.textType.value),
		readonlyScript:HTMLEncode(temp.readonlyScript.value),
		fieldtype:"VALUE_TYPE_VARCHAR",
		processDescription:HTMLEncode(createRelStr()),
		filtercondition:HTMLEncode(temp.filtercondition.value),
		refreshOnChanged:HTMLEncode(temp.refreshOnChanged.checked+""),
		calculateOnRefresh:HTMLEncode(temp.calculateOnRefresh.checked+""),
		mobile: HTMLEncode(temp.mobile.checked+""),
		validateLibs:HTMLEncode(libs),
		editMode:HTMLEncode(ed),
		processDescription:HTMLEncode( createRelStr())
	});
}

// 初始值  下拉提示框
function InitDocument(){
	// 修改状态时取值
	var editMode;
	if (oActiveEl){
		try{
			temp.name.value = HTMLDencode(oActiveEl.name);
			temp.refreshOnChanged.checked = oActiveEl.refreshOnChanged == "true";
			temp.calculateOnRefresh.checked = oActiveEl.calculateOnRefresh == "true";
			temp.discript.value = HTMLDencode(oActiveEl.discript);
			temp.valueScript.value = HTMLDencode(oActiveEl.valueScript);
			temp.optionsScript.value = HTMLDencode(oActiveEl.optionsScript);
			temp.validateRule.value = HTMLDencode(oActiveEl.validateRule);
			if(oActiveEl.hiddenScript!=null){
				temp.hiddenScript.value = HTMLDencode(oActiveEl.hiddenScript);
			}

			if(oActiveEl.hiddenValue!=null){
				temp.hiddenValue.value = HTMLDencode(oActiveEl.hiddenValue);
			}

			if(oActiveEl.hiddenPrintScript!=null){
				temp.hiddenPrintScript.value = HTMLDencode(oActiveEl.hiddenPrintScript);
			}

			if(oActiveEl.printHiddenValue!=null){
				temp.printHiddenValue.value = HTMLDencode(oActiveEl.printHiddenValue);
			}
			temp.filtercondition.value =HTMLDencode(oActiveEl.filtercondition);
			temp.readonlyScript.value = HTMLDencode(oActiveEl.readonlyScript);
			temp.mobile.checked = oActiveEl.mobile == "true";
		    var items=HTMLDencode(oActiveEl.processDescription);
		    parseRelStr(items);
			editMode= HTMLDencode(oActiveEl.editMode);
			if(oActiveEl.textType==null) {
			   oActiveEl.textType='text';
			}
			
			temp.textType.value = HTMLDencode(oActiveEl.textType);
			
			var libstr=HTMLDencode(oActiveEl.validateLibs);
			var lib=libstr.split(';');
			var validateLibs=document.getElementsByName('validateLibs');
		    for(var i=0; i< lib.length; i++){
		    	for(var j=0; j< validateLibs.length; j++){
	   				if(validateLibs[j].value==lib[i]){
	   					validateLibs[j].checked=true;
	   				}
	   			}
	   		}
		}catch(ex) {
			//alert(ex);
		}
	}
	
	initForm();
	modeChange(editMode);
	dialog.SetOkButton( true ) ;
	dialog.SetAutoSize( true ) ;
	SelectField( 'name' ) ;
	window.top.toThisHelpPage("application_module_form_info_advance_suggest");
}

//点击取消
function ev_cancel() {
  window.close();
}

// 点击返回
function Ok(){
	var isok=true;
	for(var i=0;i<document.all("editMode").length;i++){
		   if(document.all("editMode")[i].checked){
		    if(document.all("editMode")[0].checked){
		     isok=createItems();
		     if(!isok){
		         return false;
		     }
		      temp.valueScript.value="";
		    }else{
		      temp.processDescription.value="";
		      temp.filtercondition.value="";
		    }
		  
	      }
	  }
	if(!ev_check())
		return false;

	oEditor.FCKUndo.SaveUndoStep() ;
	oActiveEl = getCreateNamedElement();
	
	return true;
}

//检查内容是否完成正确
function ev_check(){
   if(temp.name.value==''){
 	 alert("{*[page.name.notexist]*}");
	  return false;
   }
   return !checkStartChar(temp.name.value);
}

function checkStartChar(value){
	return IsDigit(value,"{*[page.name.startingit]*}");
}
function IsDigit(s,msg){
	var text = s.substring(0,1);
	var patrn=/^[0-9]{1}$/; 
	if(s=="action"){
	   	alert("action为关键字，不能作为字段名！");
	   	return true;
   	}else if (patrn.exec(text)){
		alert(msg);
		return true;
	}
	return false;
} 

</script>

</HEAD>

<BODY onload="InitDocument()">

<form name="temp">
<table border=0 cellpadding=3 cellspacing=0 >
<tr>
	<td class="card" onclick="cardClick(1)" id="card1">{*[Basic]*}</td>
	<td width=2></td>
	<td class="card" onclick="cardClick(2)" id="card2">{*[Value_Script]*}</td>
	<td width=2></td>
	<td class="card" onclick="cardClick(3)" id="card3">{*[Option_Script]*}</td>
	<td width=2></td>
	<td class="card" onclick="cardClick(4)" id="card4">{*[Validate_Script]*}</td>
	<td width=2></td>
	<td class="card" onclick="cardClick(5)" id="card5">{*[Hidden_Script]*}</td>
	<td width=2></td>
	<td class="card" onclick="cardClick(6)" id="card6">{*[Hidden_Print_Script]*}</td>
	<td width=2></td>
	<td class="card" onclick="cardClick(7)" id="card7">{*[ReadOnly_Script]*}</td>
	<td width=2></td>
</tr>
<tr>
	<td valign="middle" colspan="13" bgcolor="#ffffff" align="center" width="100%">
	
	<table border=1 cellpadding=3 cellspacing=1 class="content" width="100%" id="content1">
	
	<tr>
		<td class="commFont commLabel">{*[Name]*}:</td>
		<td><input type=text name="name" onchange="checkStartChar(this.value);"/></td>
		<td class="commFont commLabel">{*[TextType]*}:</td>
		<td><select name="textType">
			<option value="text" selected="selected">{*[Common]*}</option>
			<option value="readonly">{*[Readonly]*}</option>
			<option value="hidden">{*[Hidden]*}</option>
			</select>
		</td>
	</tr>
	<tr>
		<td colspan="4" align="center">
			<input type=checkbox name="refreshOnChanged" value="true">{*[Refresh]*}&nbsp;
			<input type=checkbox name="calculateOnRefresh" value="true">{*[Recalculate]*}&nbsp;
			<input type=checkbox name="mobile" value="true" checked />{*[Mobile]*}&nbsp;
		</td>
	</tr>
	<tr>
		<td class="commFont commLabel">{*[Description]*}:</td>
		<td colspan="3"><textarea name="discript" style="width:100%"  rows="7"></textarea></td>
	</tr>
	</table>
	
	<table border=1 cellpadding=3 cellspacing=1 class="content" id="content2" style="width:100%">
	<tr>
		<%@include file="../../dialog/commondialog.jsp"%>
	</tr>
	</table>
	
	<table border=1 cellpadding=3 cellspacing=1 class="content" id="content3" style="width:100%">
	<tr>
		<td><textarea name="optionsScript" style="width:96%" rows="10"></textarea>
		<button style="border:0px;cursor: pointer;" onclick="openIscriptEditor('optionsScript','{*[Script]*}{*[Editor]*}','{*[Option_Script]*}','name','{*[Save]*}{*[Success]*}');"><img alt="Open with IscriptEditor" src="<ww:url value='/resource/image/editor.png' />"/></button>
		</td>
	</tr>
	</table>

	<table border=1 cellpadding=3 cellspacing=1 class="content" id="content4" style="width:100%">
	<tr>
	    <td width="25%">
	    <table>
	    <%
	    String applicationid = request.getParameter("application");
	    ValidateRepositoryHelper vrhpler = new ValidateRepositoryHelper();
		Map map = vrhpler.get_validate(applicationid);
			for (Iterator iter = map.keySet().iterator(); iter.hasNext();) {
				Object  id = (Object) iter.next();
				String name=(String)map.get(id);
	     %><tr><td>
	      <input type="checkbox" name="validateLibs" value="<%=(String)id %>" /><%=name%>
	     </td></tr>
	     <%}%>
	    </table>
	    </td>
		<td width="75%"><textarea name="validateRule" style="width:95%"  rows="10"></textarea>
		<button style="border:0px;cursor: pointer;" onclick="openIscriptEditor('validateRule','{*[Script]*}{*[Editor]*}','{*[Validate_Script]*}','name','{*[Save]*}{*[Success]*}');"><img alt="Open with IscriptEditor" src="<ww:url value='/resource/image/editor.png' />"/></button>
		</td>
	</tr>
	</table>

	<table border=1 cellpadding=3 cellspacing=1 class="content" id="content5" width="100%">
	<tr>
		<td><textarea name="hiddenScript" style="width:96%"  rows="10"></textarea>
		<button style="border:0px;cursor: pointer;" onclick="openIscriptEditor('hiddenScript','{*[Script]*}{*[Editor]*}','{*[Hidden_Script]*}','name','{*[Save]*}{*[Success]*}');"><img alt="Open with IscriptEditor" src="<ww:url value='/resource/image/editor.png' />"/></button>
		</td>
	</tr>
	<tr>
		<td>{*[hiddenValue]*}：<input id="hiddenValue" type="text" name="hiddenValue" /></td>
	</tr>
	</table>
	
	<table border=1 cellpadding=3 cellspacing=1 class="content" id="content6" width="100%">
	<tr>
		<td><textarea name="hiddenPrintScript" style="width:96%"  rows="10"></textarea>
		<button style="border:0px;cursor: pointer;" onclick="openIscriptEditor('hiddenPrintScript','{*[Script]*}{*[Editor]*}','{*[Hidden_Print_Script]*}','name','{*[Save]*}{*[Success]*}');"><img alt="Open with IscriptEditor" src="<ww:url value='/resource/image/editor.png' />"/></button>
		</td>
	</tr>
	<tr>
		<td>{*[Print]*}{*[hiddenValue]*}：<input  type="text" name="printHiddenValue" /></td>
	</tr>
	</table>
	
	<table border=1 cellpadding=3 cellspacing=1 class="content" id="content7" width="100%">
	<tr> 
		<td><textarea name="readonlyScript" style="width:96%" rows="10"></textarea>
		<button style="border:0px;cursor: pointer;" onclick="openIscriptEditor('readonlyScript','{*[Script]*}{*[Editor]*}','{*[ReadOnly_Script]*}','name','{*[Save]*}{*[Success]*}');"><img alt="Open with IscriptEditor" src="<ww:url value='/resource/image/editor.png' />"/></button>
		</td>
	</tr>
	</table>
	
	</td>
</tr>
</table>
</form>

<script language=javascript>
cardClick(1);
</script>

</BODY>
</o:MultiLanguage>
</HTML>
